<html
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">

    <ui:composition template="layout.xhtml">

        <ui:define name="title">
            Protocolo
        </ui:define>

        <ui:define name="breadcrumb">
            <div class="breadcrumb_divider"></div>
            <a href="pesquisarProtocolo.xhtml">Protocolo</a>
            <div class="breadcrumb_divider"></div>
            <a class="current">Pesquisar</a>
        </ui:define>

        <ui:define name="sidebar">
            <div class="gn-scroller">
                <ul class="gn-menu">
                    <li>
                        <a class="gn-icon gn-icon-add" href="criarProtocolo.xhtml">Cadastrar</a>
                    </li>
                    <li>
                        <a class="gn-icon gn-icon-pesquisar" href="pesquisarProtocolo.xhtml">Pesquisar</a>
                    </li>
                </ul>
            </div>
        </ui:define>        

        <ui:define name="content">           
            <h:form id="pesquisarProtocoForm">

                <p:messages id="pesquisarProtocoMessages" autoUpdate="true" />

                <fieldset>
                    <legend> <h4 style="margin:0 0 10px 0">Filtros</h4></legend>

                    <p:panel id="pesquisarProtocoPanel" styleClass="column12" style="background: none; border: none;">

                        <f:validateBean disabled="true">
                            <div class="row">
                                <div class="column1">
                                    <p:outputLabel value="Tipo" for="tipoProtocoloSelectOneMenu" />
                                </div>
                                <div class="column3">
                                    <p:selectOneMenu id="tipoProtocoloSelectOneMenu"
                                                     value="#{ managerPesquisarProtocolo.protocoloPesquisar.tipoProtocolo }">
                                        <f:selectItems value="#{ enums.tiposProtocolos() }" />
                                    </p:selectOneMenu>
                                </div>                            

                                <div class="column2">
                                    <p:outputLabel value="Código" for="codigoInputText" />
                                </div>
                                <div class="column3">
                                    <p:inputText id="codigoInputText" value="#{ managerPesquisarProtocolo.protocoloPesquisar.id }"/>
                                </div>
                            </div>

                            <div class="row">
                                <div class="column1">
                                    <p:outputLabel value="Data" for="nomeInputText" />
                                </div>
                                <div class="column3">
                                    <p:calendar id="dataVigorCalendar" value="#{ managerPesquisarProtocolo.protocoloPesquisar.dataCadastro }"
                                                showOn="button" pattern="dd/MM/yyyy" locale="pt" navigator="true" />
                                </div>

                                <div class="column2">
                                    <p:outputLabel value="Cliente" for="nomeInputText" />
                                </div>
                                <div class="column5">
                                    <p:inputText id="nomeInputText" value="#{ managerPesquisarProtocolo.protocoloPesquisar.cliente.nome }"/>
                                </div>
                            </div>
                        </f:validateBean>
                    </p:panel>
                </fieldset>

                <div class="buttonAction">
                    <p:commandButton
                        id="pesquisarCommandButton" value="Pesquisar" icon="ui-icon-search" oncomplete="widthFix();"
                        styleClass="ui-priority-primary"
                        update="@form" actionListener="#{ managerPesquisarProtocolo.pesquisar() }" />
                    <p:commandButton value="Limpar" icon="ui-icon-close" update="@form" oncomplete="widthFix();"
                                     actionListener="#{ managerPesquisarProtocolo.limpar() }" />
                </div>

                <p:dataTable id="protocolosDataTable" var="protocolo" value="#{ managerPesquisarProtocolo.protocolos }"
                             rows="5" paginator="true" paginatorPosition="bottom" emptyMessage="Nenhum protocolo encontrado">

                    <p:column headerText="Opções" width="10%">
                        <div class="options3">
                            <p:button
                                title="Editar" href="criarProtocolo.xhtml?protocoloId=#{ protocolo.id }"
                                icon="ui-icon-pencil"/>
                            <p:button
                                title="Visualizar" href="visualizarProtocolo.xhtml?protocoloId=#{ protocolo.id }"
                                icon="ui-icon-search"/>
                            <p:commandButton title="Excluir" oncomplete="dialogApagar.show()" icon="ui-icon-trash">
                                <f:setPropertyActionListener target="#{ managerPesquisarProtocolo.protocoloDeletar }" value="#{ protocolo }" />
                            </p:commandButton>
                        </div>
                    </p:column>

                    <p:column headerText="Código" width="10%">
                        <h:outputText value="#{ protocolo.id }" />
                    </p:column>
                    <p:column headerText="Tipo" width="10%">
                        <h:outputText value="#{ protocolo.tipoProtocolo.nome }" />
                    </p:column>
                    <p:column headerText="Cliente" width="45%">
                        <h:outputText value="#{ protocolo.cliente.nome }" />
                    </p:column>
                    <p:column headerText="Data" width="10%">
                        <h:outputText value="#{ protocolo.dataCadastro }">
                            <f:convertDateTime pattern="dd/MM/yyyy"/>
                        </h:outputText>
                    </p:column>
                    <p:column headerText="Valor" width="15%">
                        <h:outputText value="#{ protocolo.valorTotalFermojupi + protocolo.valorTotalCartorio }">
                            <f:convertNumber type="currency" locale="pt-BR" />
                        </h:outputText>
                    </p:column>

                </p:dataTable>

                <p:dialog header="Deseja realmente excluir?" widgetVar="dialogApagar" modal="true"
                          closable="false" resizable="false" draggable="false" >
                    <div class="commandDialog">
                        <p:commandButton value="Sim" update=":pesquisarProtocoForm:protocolosDataTable"
                                         oncomplete="dialogApagar.hide()" icon="ui-icon-check" actionListener="#{ managerPesquisarProtocolo.deletar() }" />
                        <p:commandButton value="Não" icon="ui-icon-close" oncomplete="dialogApagar.hide()" />
                    </div>
                </p:dialog>

            </h:form>
        </ui:define>
    </ui:composition>

</html>